package com.ruoyi.project.jiaqin.downclass.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.jiaqin.downclass.domain.DownClass;
import com.ruoyi.project.jiaqin.downclass.service.IDownClassService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 羽绒分类Controller
 * 
 * @author admin
 * @date 2021-01-29
 */
@Controller
@RequestMapping("/jiaqin/downclass")
public class DownClassController extends BaseController
{
    private String prefix = "jiaqin/downclass";

    @Autowired
    private IDownClassService downClassService;

    @RequiresPermissions("jiaqin:downclass:view")
    @GetMapping()
    public String downclass()
    {
        return prefix + "/downclass";
    }

    /**
     * 查询羽绒分类列表
     */
    @RequiresPermissions("jiaqin:downclass:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DownClass downClass)
    {
        startPage();
        List<DownClass> list = downClassService.selectDownClassList(downClass);
        return getDataTable(list);
    }

    /**
     * 导出羽绒分类列表
     */
    @RequiresPermissions("jiaqin:downclass:export")
    @Log(title = "羽绒分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DownClass downClass)
    {
        List<DownClass> list = downClassService.selectDownClassList(downClass);
        ExcelUtil<DownClass> util = new ExcelUtil<DownClass>(DownClass.class);
        return util.exportExcel(list, "downclass");
    }

    /**
     * 新增羽绒分类
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存羽绒分类
     */
    @RequiresPermissions("jiaqin:downclass:add")
    @Log(title = "羽绒分类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DownClass downClass)
    {
        return toAjax(downClassService.insertDownClass(downClass));
    }

    /**
     * 修改羽绒分类
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        DownClass downClass = downClassService.selectDownClassById(id);
        mmap.put("downClass", downClass);
        return prefix + "/edit";
    }

    /**
     * 修改保存羽绒分类
     */
    @RequiresPermissions("jiaqin:downclass:edit")
    @Log(title = "羽绒分类", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DownClass downClass)
    {
        return toAjax(downClassService.updateDownClass(downClass));
    }

    /**
     * 删除羽绒分类
     */
    @RequiresPermissions("jiaqin:downclass:remove")
    @Log(title = "羽绒分类", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(downClassService.deleteDownClassByIds(ids));
    }
}
